<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.realname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否上线">
              <el-select placeholder="请选择" v-model="form.isShow">
                <el-option
                  v-for="item in isShowOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="医院名称">
              <el-select filterable placeholder="请选择" v-model="form.hospitalId">
                <el-option
                  v-for="item in hospOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目名称">
              <el-input v-model="form.projectName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="评价时间">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="dates"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button style="margin-left:10px" type="primary" @click="searchFn">查询</el-button>
              <!--  v-if="permissionJson.indexOf('AdminBeautyProjectOrderCommentProvider.beautyProjectOrdersCommentsListExcel') !=-1" -->
              <el-button
                style="margin-left:10px"
                type="primary"
               v-if="hasPermission('AdminBeautyProjectOrderCommentProvider.beautyProjectOrdersCommentsListExcel')"
                @click="exporfun"
              >导出</el-button>
              <router-link to="itemEvaluateAdd">
                <el-button style="margin-left:10px" type="primary"  v-if="hasPermission('AdminBeautyProjectOrderCommentProvider.saveComment')">新增</el-button>
              </router-link>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="userResponseDTO.realname" label="用户名称"></el-table-column>
        <el-table-column prop="userResponseDTO.username" label="用户手机号">
            <template slot-scope="scope">
            <div v-if="scope.row.userResponseDTO">{{scope.row.userResponseDTO.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="projectOrderResponseDTO.orderSn" label="项目订单号"></el-table-column>
        <el-table-column prop="hospitalResponseDTO.name" label="医院名称"></el-table-column>
        <el-table-column prop="projectResponseDTO.name" label="项目名称"></el-table-column>
        <el-table-column prop="contents" label="评论内容"></el-table-column>
        <el-table-column label="是否显示">
          <template slot-scope="scope">
            <el-switch
              class="switchStyle"
              v-model="scope.row.isShow"
              @click.native="changeStatus('serverAppointmentStatus',scope.row.isShow,scope.row.id)"
              active-color="#13ce66"
              inactive-color="#eee"
              :active-value="1"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="createdAt" label="评论时间"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="100"
          v-if="hasPermission('AdminBeautyProjectOrderCommentProvider.getBeautyProjectOrderCommentById')"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="toRoutes('itemEvaluateInfo',scope.row.id)"
              size="small"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {
  listBeautyProjectOrdersComments,
  updateBeautyProjectOrderCommentShow
} from "@/api/itemEvaluate";
import { hospitalDropDown } from "@/api/doctorManage";
import { exportfile } from "@/api/commjs/exprot";
export default {
  name: "itemEvaluateIndex",
  data() {
    return {
          permissionJson: JSON.parse(
                localStorage.getItem("permissionJson")
            ),
      val: "1",
      dates: [],
      tableLoading: true,
      form: {
        beginDate: null,
        endDate: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      isShowOptions: [
        {
          value: 0,
          label: "下线"
        },
        {
          value: 1,
          label: "上线"
        }
      ],
      hospOptions: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      }
    };
  },
  filters: {
    cardType: function(e) {
      return window.helper.cardType(String(e));
    }
  },
  inject: ["reload"],
  mounted() {
    this.getOption();
    this.getList(this.listForm);
  },
  methods: {
    //导出
    exporfun() {
      exportfile(
        "/com.mmk.reservation.api.AdminBeautyProjectOrderCommentProvider/1.0.0/beautyProjectOrdersCommentsListExcel.html",
        this.form
      );
    },
    //按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    getOption() {
      // 医院列表
      hospitalDropDown().then(res => {
        let resData = res.data.data;
        let newData = [];
        resData.forEach(e => {
          newData.push({
            value: e.id + "",
            label: e.name
          });
        });
        this.hospOptions = newData;
      });
    },
    //成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    //失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 路由跳转
    toRoutes(e, userId) {
      let route = { name: e, query: { userId: userId } };
      this.$router.push(route);
    },
    //查询
    searchFn() {
      // console.log(this.dates)
      this.form.pageNum = 1;
      if (this.dates) {
        if (this.dates.length > 0) {
          this.form.beginDate = this.dates[0];
          this.form.endDate = this.dates[1];
        }
      } else {
        this.form.beginDate = null;
        this.form.endDate = null;
      }
      // console.log(this.form)
      this.getList(this.form);
    },
    //上下架与状态修改
    changeStatus(type, status, id) {
      let datas = {
        isShow: status,
        id: id
      };
      // console.log(datas)
      updateBeautyProjectOrderCommentShow(datas)
        .then(res => {
          // console.log(res)
          if (res.data.code === 0) {
            this.$message({
              message: "修改成功",
              type: "success"
            });
          } else {
            this.$message.error("修改失败");
          }
          // this.reload()
        })
        .catch(error => {
          this.$message.error(error);
        });
      // console.log(datas)
    },
    //列表数据获取
    getList(e) {
      this.tableLoading = true;
      let datas = e;
      listBeautyProjectOrdersComments(datas)
        .then(res => {
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    //改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    //选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
